/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.score.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.modules.score.entity.OrganizePerson;
import com.fosung.frame.modules.score.service.OrganizePersonService;

/**
 * 参会人员表Controller
 * @author ygl
 * @version 2017-09-03
 */
@Controller
@RequestMapping(value = "${adminPath}/score/organizePerson")
public class OrganizePersonController extends BaseController {

	@Autowired
	private OrganizePersonService organizePersonService;
	
	@ModelAttribute
	public OrganizePerson get(@RequestParam(required=false) String id) {
		OrganizePerson entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = organizePersonService.get(id);
		}
		if (entity == null){
			entity = new OrganizePerson();
		}
		return entity;
	}
	
	@RequiresPermissions("score:organizePerson:view")
	@RequestMapping(value = {"list", ""})
	public String list(OrganizePerson organizePerson, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<OrganizePerson> page = organizePersonService.findPage(new Page<OrganizePerson>(request, response), organizePerson); 
		model.addAttribute("page", page);
		return "modules/score/organizePersonList";
	}

	@RequiresPermissions("score:organizePerson:view")
	@RequestMapping(value = "form")
	public String form(OrganizePerson organizePerson, Model model) {
		model.addAttribute("organizePerson", organizePerson);
		return "modules/score/organizePersonForm";
	}

	@RequiresPermissions("score:organizePerson:edit")
	@RequestMapping(value = "save")
	public String save(OrganizePerson organizePerson, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, organizePerson)){
			return form(organizePerson, model);
		}
		organizePersonService.save(organizePerson);
		addMessage(redirectAttributes, "保存参会人员表成功");
		return "redirect:"+Global.getAdminPath()+"/score/organizePerson/?repage";
	}
	
	@RequiresPermissions("score:organizePerson:edit")
	@RequestMapping(value = "delete")
	public String delete(OrganizePerson organizePerson, RedirectAttributes redirectAttributes) {
		organizePersonService.delete(organizePerson);
		addMessage(redirectAttributes, "删除参会人员表成功");
		return "redirect:"+Global.getAdminPath()+"/score/organizePerson/?repage";
	}

}